/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package _asm_app;

import _entity.CartItem;
import _entity.OrdersInfo;
import _entity.ProductInfo;
import bean.CategoriesBeanRemote;
import bean.OrdersBeanRemote;
import bean.ProductsBeanRemote;
import bean.RolesBeanRemote;
import bean.ShoppingCartRemote;
import bean.UsersBeanRemote;
import java.math.BigDecimal;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

/**
 *
 * @author HP
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args){
        
//        ProductsBeanRemote remote = lookupProductsBeanRemote();
//        ProductInfo p = remote.find(1);
//        System.out.println(p.getName());
//        p.setName("ppppppp");
//        remote.edit(p);

//        System.out.println(getSize());
//        ProductsBeanRemote remote = lookupProductsBeanRemote();
//        System.out.println(remote.find(1).getName());
//        System.out.println(remote.findAll().size());
//
//        RolesBeanRemote remote2 = lookupRolesBeanRemote();
//        RoleInfo r = remote2.find("admin");
//        r.setDescription("description");
//        remote2.edit(r);
//        System.out.println(remote2.find("admin").getRoleName());
//        System.out.println(remote2.findAll().size());
//
//        UsersBeanRemote uRe = lookupUsersBeanRemote();
//        UserInfo i = uRe.find("aaa");
//        i.setEmail("eee@fff.ggg");
//        uRe.edit(i);
//
        ShoppingCartRemote remote4 = lookupShoppingCartRemote();
        CartItem item = new CartItem();
        ProductInfo p = new ProductInfo();
        p.setId(1);
        p.setPrice(new BigDecimal("44"));
        item.setQuantity(3);
        item.setProduct(p);

        remote4.add(item);

        System.out.println(remote4.saveShoppingCart());
//        System.out.println(remote4.getAll().size());

//        OrdersBeanRemote oRe = lookupOrdersBeanRemote();
//        OrdersInfo i = oRe.find(1);
//        i.setIsEnable(false);
//        oRe.update(i);
    }

    public static int getSize(){
        CategoriesBeanRemote remote = lookupCategoriesBeanRemote();
       return remote.findAll().size();
    }

    private static CategoriesBeanRemote lookupCategoriesBeanRemote() {
        try {
            Context c = new InitialContext();
            return (CategoriesBeanRemote) c.lookup("java:global/_asm/CategoriesBean!bean.CategoriesBeanRemote");
        } catch (NamingException ne) {
          //  Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
            throw new RuntimeException(ne);
        }
    }

    private static ProductsBeanRemote lookupProductsBeanRemote() {
        try {
            Context c = new InitialContext();
            return (ProductsBeanRemote) c.lookup("java:global/_asm/ProductsBean!bean.ProductsBeanRemote");
        } catch (NamingException ne) {
           // Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
            throw new RuntimeException(ne);
        }
    }

    private static RolesBeanRemote lookupRolesBeanRemote() {
        try {
            Context c = new InitialContext();
            return (RolesBeanRemote) c.lookup("java:global/_asm/RolesBean!bean.RolesBeanRemote");
        } catch (NamingException ne) {
           // Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
            throw new RuntimeException(ne);
        }
    }

    private static  UsersBeanRemote lookupUsersBeanRemote() {
        try {
            Context c = new InitialContext();
            return (UsersBeanRemote) c.lookup("java:global/_asm/UsersBean!bean.UsersBeanRemote");
        } catch (NamingException ne) {
           // Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
            throw new RuntimeException(ne);
        }
    }

    private static ShoppingCartRemote lookupShoppingCartRemote() {
        try {
            Context c = new InitialContext();
            return (ShoppingCartRemote) c.lookup("java:global/_asm/ShoppingCart!bean.ShoppingCartRemote");
        } catch (NamingException ne) {
           // Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
            throw new RuntimeException(ne);
        }
    }

    private static OrdersBeanRemote lookupOrdersBeanRemote() {
        try {
            Context c = new InitialContext();
            return (OrdersBeanRemote) c.lookup("java:global/_asm/OrdersBean!bean.OrdersBeanRemote");
        } catch (NamingException ne) {
           // Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
            throw new RuntimeException(ne);
        }
    }
}
